#include<bits/stdc++.h>
#define int long long
using namespace std;
int g[200001],n;
int rr[200001],rb[200001];
int dfs(int dep){
    int maxscore=0;
    if(dep==n){
        if(g[rr[dep-1]]==g[dep]){
            maxscore=g[rr[dep-1]];
        }
        if(g[rb[dep-1]]==g[dep]){
            maxscore=max(maxscore,g[rb[dep-1]]);
        }
        return maxscore;
    }
    rr[dep]=dep;
    rb[dep]=rb[dep-1];
    if(g[rr[dep-1]]==g[dep]){
        maxscore=g[rr[dep-1]]+dfs(dep+1);
    }else{
        maxscore=dfs(dep+1);
    }
    rr[dep]=rr[dep-1];
    rb[dep]=dep;
    if(g[rb[dep-1]]==g[dep]){
        maxscore=max(maxscore,g[rb[dep-1]]+dfs(dep+1));
    }else{
        maxscore=max(maxscore,dfs(dep+1));
    }
    return maxscore;
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%lld",&T);
    while(T--){
        scanf("%lld",&n);
        g[0]=0;
        rr[0]=0;
        rb[0]=0;
        for(int i=1;i<=n;i++){
            scanf("%lld",&g[i]);
        }
        printf("%lld\n",dfs(0));
        for(int i=0;i<n;i++){
            rr[i]=0,rb[i]=0;
        }
    }
    return 0;
}
